package com.xingda.packing.dmss.led.impl;

import com.xingda.packing.dmss.led.LedConnService;
import com.xingda.packing.dmss.led.LedHelper;
import com.xingda.packing.dmss.led.LedOperateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.net.Socket;
import java.util.Objects;

@Slf4j
@Component
public class LedOperateServiceImpl implements LedOperateService {

    @Resource
    LedConnService ledConnService;

    @Override
    public void write(String content, String ip, int port) {
        Socket socket = ledConnService.getConn(ip, port);
        if (Objects.isNull(socket)) {
            log.info("socket 为空，ip-{} ,port-{}", ip, port);
            return;
        }

        log.info("====write的socket；{}", socket);
//        发送一次
        LedHelper.send(content, socket);

//        发送三次
//        for (int i = 0; i < 3; i++) {
//            log.info("====write发送第i:{}次", i);
//            LedHelper.send(content, socket);
//        }
    }
}
